package com.wyp168.leetcode;

/**
 * @ClassName OrderOfLargestPlusSignSolution
 * @Title TODO
 * @Description TODO
 * @Author wyp168
 * @Date 2022/11/9 00:24
 */
public class OrderOfLargestPlusSignSolution {
    public static void main(String[] args) {
        OrderOfLargestPlusSignSolution solution = new OrderOfLargestPlusSignSolution();
        int n = 1;
        int[][] mines = {{0, 0}};
        System.out.println(solution.orderOfLargestPlusSign(n, mines));
    }

    public int orderOfLargestPlusSign(int n, int[][] mines) {
        int[][] grid = new int[n][n];
        int[][] dest = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
        for (int[] mine : mines) {
            grid[mine[0]][mine[1]] = 1;
        }
        int result = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (grid[i][j] != 1) {
                    int tempLevel = n;
                    for (int k = 0; k < 4; k++) {
                        int tempCount = 1;
                        int xIndex = i;
                        int yIndex = j;
//                    while (grid[xIndex = xIndex + dest[k][0]][yIndex = yIndex + dest[k][1]] != 1) {
//                        tempCount ++;
//                    }

                        while (true) {
                            xIndex += dest[k][0];
                            yIndex += dest[k][1];
                            if (xIndex >= 0 && xIndex < n && yIndex >= 0 && yIndex < n) {
                                if (grid[xIndex][yIndex] != 1) {
                                    tempCount++;
                                    continue;
                                }
                                break;
                            }
                            break;
                        }

                        tempLevel = Math.min(tempCount, tempLevel);
                    }

                    result = Math.max(result, tempLevel);
                }
            }
        }
        return result;
    }
}
